<template>
  <div class="box">
    <div class="container">
      <el-row :gutter="20" class="row">
        <el-col :span="4" :offset="0">
          <el-card shadow="always" :body-style="{ padding: '20px' }" class="left-container">
            <div>
              <div class="header" ref="header">
                <img src="https://element-plus.org/images/element-plus-logo.svg" alt="" />
                <span>后台管理</span>
              </div>

              <el-divider ref="divider"></el-divider>

              <div class="scroll-container" ref="scroll">
                <el-scrollbar class="left-scroll-container" :height="height">
                  <el-menu :default-openeds="['1', '5']">
                    <el-menu-item index="1-1">
                      <router-link to="/Manager" class="link">控制面板</router-link>
                    </el-menu-item>
                    <el-sub-menu index="2">
                      <template #title>文章</template>
                      <el-menu-item-group>
                        <template #title>博客管理</template>
                        <el-menu-item index="2-1">
                          <router-link to="/Manager/Article/List" class="link"
                            >博客列表</router-link
                          >
                        </el-menu-item>
                        <el-menu-item index="2-2">
                          <router-link to="/Manager/WriteBlog" class="link">书写博客</router-link>
                        </el-menu-item>
                      </el-menu-item-group>
                    </el-sub-menu>

                    <el-sub-menu index="3">
                      <template #title>分类</template>
                      <el-menu-item-group>
                        <template #title>类别管理</template>
                        <el-menu-item index="3-1">类别列表</el-menu-item>
                      </el-menu-item-group>
                    </el-sub-menu>

                    <el-sub-menu index="4">
                      <template #title>标签</template>
                      <el-menu-item-group>
                        <template #title>标签管理</template>
                        <el-menu-item index="4-1">标签列表</el-menu-item>
                      </el-menu-item-group>
                    </el-sub-menu>
                  </el-menu>
                </el-scrollbar>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="20" :offset="0">
          <router-view></router-view>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      height: 0,
    };
  },
  mounted() {
    const height =
      document.documentElement.clientHeight -
      this.$refs.header.offsetHeight -
      this.$refs.divider.$el.offsetHeight +
      24 * 2;
    this.height = height;
  },
  created() {
    window.onresize = () => {
      const height =
        document.documentElement.clientHeight -
        this.$refs.header.offsetHeight -
        this.$refs.divider.$el.offsetHeight +
        24 * 2;
      this.height = height;
    };
  },
};
</script>

<style scoped>
.box {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  overflow: hidden;
}
.left-container,
.container,
.row {
  height: 100%;
  min-height: 100%;
}
.header {
  display: flex;
  justify-content: center;
  align-items: center;
}
.header img {
  width: 5rem;
  margin-right: 0.5rem;
}

:deep() .el-scrollbar,
.el-scrollbar__wrap {
  max-height: 600px;
  overflow-x: hidden;
}
.left-scroll-container {
  overflow: hidden;
}
.link {
  width: 100%;
  display: inline-block;
  text-decoration: none;
  color: black;
  padding-left: 40px;
}
:deep() .el-menu-item {
  padding: 0px;
  padding-left: 0px !important;
}
</style>
